package com.j.lemon.learn.pulsar;

import org.apache.pulsar.client.admin.PulsarAdmin;
import org.apache.pulsar.client.api.PulsarClient;
import org.apache.pulsar.client.api.PulsarClientException;

/**
 * @Author lijunjun
 * @Date 2020-07-06 14:48
 * @Description
 */
public class PulsarUtils {
    private static volatile PulsarClient client=null;
    private static volatile PulsarAdmin admin = null;

    public static PulsarClient getClient() throws PulsarClientException {
            if(client==null){
                synchronized (PulsarUtils.class){
                    if(client==null){
                        client = PulsarClient.builder()
                                .serviceUrl("pulsar://10.21.171.58:6650,pulsar://10.21.171.59:6650,pulsar://10.21.171.60:6650")
                                .build();
                    }
                }
            }
            return client;
    }
    public static PulsarAdmin getAdmin() throws PulsarClientException {
            if(admin==null){
                synchronized (PulsarUtils.class){
                    if(admin==null){
                        String url = "http://10.21.171.60:8080";
                        boolean tlsAllowInsecureConnection = false;
                        String tlsTrustCertsFilePath = null;
                        admin = PulsarAdmin.builder()
//                .authentication(authPluginClassName,authParams)
                                .serviceHttpUrl(url)
                                .tlsTrustCertsFilePath(tlsTrustCertsFilePath)
                                .allowTlsInsecureConnection(tlsAllowInsecureConnection)
                                .build();

                    }
                }
            }
            return admin;
    }
}
